#include <stdio.h>
#include <stdlib.h>

#include "gravaoss.h"

int main (int argc, char *argv[])
{
	short *buffer;
	FILE *fp;
	long tamanho;
	int maxtime=5; // maximun recording time (in seconds)
	int fs=11025;
	
	// Gravando locução a ser reconhecida
	buffer=(short *)malloc(maxtime*sizeof(short)*fs); // maxtime*2bytes*fs
	
	tamanho = gravaoss(buffer,maxtime,fs);
	printf("tamanho total = %ld\n",tamanho);
	
    // Saving recorded utterance in file 
    if ((fp = fopen("sound.raw", "wb"))==NULL)
    {
    	printf("Cannot open file \n");
        exit(1);
    }
    if (fwrite(buffer, sizeof(short), tamanho, fp) != tamanho)
    {
    	printf("Write error occurred");
        exit(1);
    }
    fclose(fp); 
	
	
	free(buffer);

	return 0;
}
